#ifndef MESSAGE_H
#define MESSAGE_H

#include <string>
#include <ctime>

//基类：消息
class Message
{
private:
    std::string sender;
    time_t timestamp;
public:
    Message(const std::string& sender):sender(sender),timestamp(time(nullptr)){}
    
    virtual std::string format() const
    {
        return "[" + std::string(ctime(&timestamp)) + "]" +sender + ":" ;
    }

    virtual ~Message(){};
};


//继承Message的文本消息类
class TextMessage : public Message
{
private:
    std::string content;

public:
    TextMessage(const std::string& sender,const std::string& content):Message(sender),content(content){}

    //重写虚函数
    std::string format() const override
    {
        return Message::format() + content;
    }
};



#endif